package com.ruoyi.user.identity.service.impl;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.user.identity.mapper.IdentityVerificationMapper;
import com.ruoyi.common.IdentityVerification;
import com.ruoyi.user.identity.service.IIdentityVerificationService;

/**
 * 实名认证Service业务层处理
 * 
 * @author slk
 * @date 2025-09-17
 */
@Service
public class IdentityVerificationServiceImpl implements IIdentityVerificationService 
{
    @Autowired
    private IdentityVerificationMapper identityVerificationMapper;

    /**
     * 查询实名认证
     * 
     * @param id 实名认证主键
     * @return 实名认证
     */
    @Override
    public IdentityVerification selectIdentityVerificationById(Integer id)
    {
        return identityVerificationMapper.selectIdentityVerificationById(id);
    }

    /**
     * 查询实名认证列表
     * 
     * @param identityVerification 实名认证
     * @return 实名认证
     */
    @Override
    public List<IdentityVerification> selectIdentityVerificationList(IdentityVerification identityVerification)
    {
        return identityVerificationMapper.selectIdentityVerificationList(identityVerification);
    }

    /**
     * 全查实名认证列表（不分页，过滤逻辑删除）
     * 
     * @param identityVerification 实名认证
     * @return 实名认证
     */
    @Override
    public List<IdentityVerification> selectAllIdentityVerification(IdentityVerification identityVerification)
    {
        return identityVerificationMapper.selectAllIdentityVerification(identityVerification);
    }

    /**
     * 新增实名认证
     * 
     * @param identityVerification 实名认证
     * @return 结果
     */
    @Override
    public int insertIdentityVerification(IdentityVerification identityVerification)
    {
        return identityVerificationMapper.insertIdentityVerification(identityVerification);
    }

    /**
     * 修改实名认证
     * 
     * @param identityVerification 实名认证
     * @return 结果
     */
    @Override
    public int updateIdentityVerification(IdentityVerification identityVerification)
    {
        return identityVerificationMapper.updateIdentityVerification(identityVerification);
    }

    /**
     * 批量删除实名认证
     * 
     * @param ids 需要删除的实名认证主键
     * @return 结果
     */
    @Override
    public int deleteIdentityVerificationByIds(Integer[] ids)
    {
        return identityVerificationMapper.deleteIdentityVerificationByIds(ids);
    }

    /**
     * 删除实名认证信息
     * 
     * @param id 实名认证主键
     * @return 结果
     */
    @Override
    public int deleteIdentityVerificationById(Integer id)
    {
        return identityVerificationMapper.deleteIdentityVerificationById(id);
    }

    /**
     * 根据用户ID查询实名认证信息
     * 
     * @param uid 用户ID
     * @return 实名认证信息
     */
    @Override
    public IdentityVerification selectIdentityVerificationByUid(Long uid)
    {
        return identityVerificationMapper.selectIdentityVerificationByUid(uid);
    }

    /**
     * 保存或更新用户身份认证信息
     * 
     * @param identityVerification 身份认证信息
     * @return 结果
     */
    @Override
    public int saveOrUpdateIdentityVerification(IdentityVerification identityVerification)
    {
        // 先查询是否已存在该用户的身份认证信息
        IdentityVerification existing = identityVerificationMapper.selectIdentityVerificationByUid(identityVerification.getUid());
        
        if (existing != null) {
            // 存在则更新
            identityVerification.setId(existing.getId());
            return identityVerificationMapper.updateIdentityVerification(identityVerification);
        } else {
            // 不存在则新增
            return identityVerificationMapper.insertIdentityVerification(identityVerification);
        }
    }
}
